package com.example.auth.Controller;

import com.example.auth.Config.Config;
import com.example.auth.Feign.ProductFeign;
import com.example.auth.Service.ExamService;
import com.example.auth.entity.CommonResult;
import com.example.auth.entity.Exam;
import com.example.common.Config.SwaggerConfig;
import com.example.common.Config.TestSwaggerConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@RestController
@RequestMapping("/authtest")
@Api(value = "auth服务",tags = {"auth服务"})
@Slf4j
public class AuthController {

    @Value("${spring.datasource.username}")
    private String username;

    @Value("${config.test}")
    private String test;

    @Value("${service.desc}")
    private String desc;

//    @Resource
//    private TestSwaggerConfig testSwaggerConfig;

    @Resource
    private ExamService examService;

    @Resource
    private ProductFeign productFeign;

    @ApiOperation(value = "测试gateway转发",tags = "获取跨服务查询数据")
    @GetMapping("/getTest")
    public String testAuth(){
        return desc+username+test;
    }

    @ApiOperation(value = "插入数据",tags = "数据")
    @PostMapping("/save")
    public CommonResult<Boolean> save(@RequestBody Exam exam){
        if (Objects.isNull(exam)){
            throw new RuntimeException("数据不可为空");
        }
        boolean save = examService.save(exam);
        return CommonResult.success(save);
    }

    @ApiOperation(value = "获取product跨服务查询数据",tags = "获取跨服务查询数据")
    @GetMapping("/getFeign")
    public CommonResult<String> getFeign(){
        String product = productFeign.getProduct();
        return CommonResult.success(product);
    }

}
